#测试系统登陆页
import time

from selenium.webdriver.common.by import By

from commond.Utils import ForumDriver


class ForumLogin:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)

    #页面元素检查
    def Check_Ele_Login(self):
        #检查   ”用户登陆“
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")

        #检查用户名输入框，密码输入框
        self.driver.find_element(By.CSS_SELECTOR,"#username")
        self.driver.find_element(By.CSS_SELECTOR,"#password")

        #检查用户名提示符，密码提示符，可见密码
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-3 > label")
        self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > label")
        self.driver.find_element(By.CSS_SELECTOR,"#password_a > svg")

        #检查登陆按钮
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        #检查”点击注册“
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a")

    #登陆失败测试用例
    def Fail_Login(self):
        #正确的用户名和错误的密码
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("mxj")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("mxj")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        time.sleep(1)

        #错误的用户名和错误的密码
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("mxj2")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("mxj")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        time.sleep(1)

        #错误的用户名和正确的密码
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("mxj88")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        time.sleep(1)

#成功登陆测试用例
    def Suc_Login(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("mxj")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        #如何确认是否登陆成功 ---
        self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title")

    def Suc_Login_mxj2(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("mxj2")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        #如何确认是否登陆成功 ---
        self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title")

    def Suc_Login_mxj4(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("mxj4")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        #如何确认是否登陆成功 ---
        self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title")
    #测试回复私信是否收到
    def Suc_Login_CheckmMsg(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        time.sleep(2)
        #通过截图判断是否收到私信回复
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_offcanvasEnd > div.offcanvas-header > button").click()

    #注册功能
    def Login_To_Enroll(self):
        self.url="http://127.0.0.1:9580/sign-up.html"
        self.driver.get(self.url)










Login=ForumLogin()
# test.Check_Ele_Login()
# test.Fail_Login()
# test.Suc_Login()
